#include"../mqsever/mq_exchange.hpp"
#include<gtest/gtest.h>
mymq::ExchangeManager::ptr emp;
class ExchangeTest:public testing::Environment{
        // Override this to define how to set up the environment.
    virtual void SetUp() {
        std::cout<<"单元测试前的初始化"<<std::endl;
        emp = std::make_shared<mymq::ExchangeManager>("./data/meta.db");
    }

    // Override this to define how to tear down the environment.
    virtual void TearDown() {
        //emp->clear();
        std::cout<<"单元测试结束后的清理"<<std::endl;

    }
};
TEST(exchange_test,insert_test)
{
    //std::unordered_map<std::string, std::string> map;
    // emp->declareExchange("exchange1",mymq::ExchangeType::DIRECT,true,false,map);
    // emp->declareExchange("exchange2",mymq::ExchangeType::DIRECT,true,false,map);
    // emp->declareExchange("exchange3",mymq::ExchangeType::DIRECT,true,false,map);
    // emp->declareExchange("exchange4",mymq::ExchangeType::DIRECT,true,false,map);
    // ASSERT_EQ(emp->size(),4);
}
TEST(exchange_test,select_test){
    ASSERT_EQ(emp->exists("exchange1"),false);
    ASSERT_EQ(emp->exists("exchange2"),false);
    ASSERT_EQ(emp->exists("exchange3"),true);
    ASSERT_EQ(emp->exists("exchange4"),true);

    mymq::Exchange::ptr exp = emp->selectExchange("exchange2");
    ASSERT_NE(exp.get(),nullptr);
    ASSERT_EQ(exp->type,mymq::ExchangeType::DIRECT);
    ASSERT_EQ(exp->name,"exchange2");
    ASSERT_EQ(exp->durable,true);
    //std::cout<<int(exp->auto_delete)<<"==================="<<std::endl;
    ASSERT_EQ(exp->auto_delete,false);
    //std::cout<<exp->getArgs()<<std::endl;
    //ASSERT_EQ(exp->getArgs(),std::string("k2=v2&k1=v12"));
    // for(auto a:exp->args)
    // {
    //     std::cout<<a.first<<" ";
    //     std::cout<<a.second<<std::endl;
    //     std::cout<<"========================================"<<std::endl;
    // }
}

TEST(exchange_test,remove_test){
    // emp->deleteExchange("exchange2");
    // mymq::Exchange::ptr exp = emp->selectExchange("exchange2");
    // ASSERT_EQ(exp.get(),nullptr);
    // ASSERT_EQ(emp->exists("exchange2"),false);


}
int main(int argc,char* argv[])
{
    testing::InitGoogleTest(&argc,argv);
    testing::AddGlobalTestEnvironment(new ExchangeTest);
    int ret = RUN_ALL_TESTS();
    return 0;
}